package com.android.interfata;

import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;


public class AddProductAlarm extends Activity
{
	double price = 0.0;
	double procent = 0.0;
	EditText priceET, procentET; 
	
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.add_alarm);
		
		Button addAlarmBtn = (Button) findViewById(R.id.addAlarmBtn);
		addAlarmBtn.setOnClickListener(new View.OnClickListener()
        {				
			public void onClick(View v) 
			{
				
				priceET = (EditText) findViewById(R.id.priceProductAlarm);
				procentET= (EditText) findViewById(R.id.procentProductAlarm); 
				
				checkData();
														
			}
		});
		
     	
	}
	
	private void checkData()
    {
		if ( checkString(priceET.getText().toString()) == false || checkString(procentET.getText().toString()) == false)
		{
			System.out.println("checkData  ");
			AlertDialog.Builder dlgAlert  = new AlertDialog.Builder(this);
			dlgAlert.setMessage("Please insert digits!");
	        dlgAlert.setTitle("Warning");
	        dlgAlert.setPositiveButton("OK", null);
	        dlgAlert.setCancelable(true);
	        dlgAlert.create().show();
		}
		else
		{
			System.out.println("AddProductAlaram  ");
			if (priceET.getText().toString().equals("") == true)
				price = 0.0;
			else
				price = Double.parseDouble(priceET.getText().toString());
			
			  
			if (procentET.getText().toString().equals("") == true)
				procent = 0.0;
			else
				procent =  Double.parseDouble(procentET.getText().toString());
			
			Product1.setPriceAlarm(price);
			Product1.setProcentAlarm(procent);
			
			Product1.pricePus = true; 
			Product1.procentPus = true;
			
			finish();
		}
    }
	
	
	public static boolean checkString(String s)
	{ 
		try
		{
			System.out.println(s);
			if (s.length() == 0)
			{
				return true;
			}
			else
			{
				Double d = Double.parseDouble(s);
				return true; 
			}
			
		}
		catch(Exception e)
		{
			System.out.println("nu e double " + e);
			return false;
		}
	 } 

}